package com.wuxiaoqin.server.controller;


import com.wuxiaoqin.server.entity.Users;
import com.wuxiaoqin.server.service.IShoppingsService;
import com.wuxiaoqin.server.service.IUsersService;
import com.wuxiaoqin.uitls.respObj.RespBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-11-03
 */
@RestController
@RequestMapping
public class ShoppingsController {

    @Autowired
    private IShoppingsService shoppingsService;
    @Autowired
    private IUsersService usersService;

    @ApiOperation(value = "加入购物车")
    @GetMapping("/addShopCart")
    public RespBean addShopCat(@RequestParam("goodsid") Integer cid,
                               @RequestParam("size") String size,HttpServletRequest request){
        Integer uId = usersService.getCurrentUser().getUId();
        return shoppingsService.addShopCart(uId,cid,size,request);
    }
    @ApiOperation(value = "购物车增加数量")
    @GetMapping("/addCartNum")
    public RespBean addCartNum(@RequestParam("cartid") Integer cartid,
                               @RequestParam("num") Integer num){
        return shoppingsService.addCartNum(cartid,num);
    }
    @ApiOperation(value = "按登录用户查询购物车")
    @GetMapping("/getCart")
    public RespBean getCart(){
        Integer uId = usersService.getCurrentUser().getUId();
        return shoppingsService.getCart(uId);
    }

    @ApiOperation(value = "修改购物车商品数量")
    @GetMapping("/ModifyCartNum")
    public RespBean ModifyCartNum(@RequestParam("cartid") Integer cartid,@RequestParam("num") Integer num){
        Integer userid = usersService.getCurrentUser().getUId();
        return shoppingsService.ModifyCartNum(userid,cartid,num);
    }


    @ApiOperation(value = "删除购物商品一个")
    @DeleteMapping("/delCart")
    public RespBean delCart(@RequestParam("cartid") Integer cartid){
        Integer userid = usersService.getCurrentUser().getUId();
        return shoppingsService.delCartOne(userid,cartid);
    }

    @ApiOperation(value = "删除购物商品一列按id")
    @DeleteMapping("/delCartById")
    public RespBean delCartById(@RequestParam("cartid") Integer cartid){
        Integer userid = usersService.getCurrentUser().getUId();
        return shoppingsService.delCart(userid,cartid);

    }

    @ApiOperation(value = "购物车数量")
    @GetMapping("/TotalCart")
    public Integer cartTotal(){
        Integer uId = usersService.getCurrentUser().getUId();
        return shoppingsService.cartTotal(uId);
    }

    @ApiOperation(value = "清空购物车")
    @DeleteMapping("/delCartAll")
    public RespBean delCartAll(){
        Integer userid = usersService.getCurrentUser().getUId();
        return shoppingsService.delCartAll(userid);

    }
    @ApiOperation(value = "被勾选")
    @GetMapping("/isSelected")
    public RespBean isSelected(@RequestParam("cartid") Integer cartid){
        Integer uId = usersService.getCurrentUser().getUId();
        return shoppingsService.isSelected(cartid,uId);
    }
    @ApiOperation(value = "没被勾选")
    @GetMapping("/noSelected")
    public RespBean noSelected(@RequestParam("cartid") Integer cartid){
        Integer uId = usersService.getCurrentUser().getUId();
        return shoppingsService.noSelected(cartid,uId);
    }


}
